package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.ConsultSpecialty;
import com.czh.springboot04.service.ConsultSpecialtyService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultspecialty")
@CrossOrigin
public class ConsultSpecialtyController {
    @Autowired
    private ConsultSpecialtyService consultSpecialtyService;

    @PostMapping("/insert")
    public R insert(@RequestBody ConsultSpecialty consultSpecialty) {
        int i = consultSpecialtyService.insert(consultSpecialty);
        if (i!= 0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }

    @PutMapping("/update")
    public R update(@RequestBody ConsultSpecialty consultSpecialty) {
        int i = consultSpecialtyService.update(consultSpecialty);
        if (i!= 0) {
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable int id) {
        int i = consultSpecialtyService.delete(id);
        if (i!= 0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }

    @GetMapping("/selectByPage")
    public R selectByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,@RequestParam(required = false,defaultValue = "8") int pageSize) {
        PageInfo<ConsultSpecialty> pageInfo = consultSpecialtyService.selectByPage(pageNum, pageSize);
//     ,ConsultSpecialty consultSpecialty   ,consultSpecialty
        return R.ok(pageInfo);
    }
    @GetMapping("/selectAll")
    public R selectAll() {
        List<ConsultSpecialty> consultSpecialtyList = consultSpecialtyService.selectAll();
        System.out.println(consultSpecialtyList);
        return R.ok(consultSpecialtyList);
    }

}
